/*
 * @Descripttion: 
 * @version: 
 * @Author: weihua.yao
 * @Date: 2020-02-27 14:46:01
 * @LastEditTime: 2020-02-27 15:59:28
 */
var a = {
  name: 'A',
  fn: function () {
    console.log(this.name)
  }
}

a.fn() //this === a
a.fn.call({
  name: 'B' //this === {name:'B'}
})
var fn1 = a.fn // this === window
fn1()

if (true) {
  var name = 'james'
}
console.log(name)


var a = 100

function foo() {
  var a = 2020
  console.log('fn', a)
}

console.log(a)

function init() {
  var name = "Mozilla"; // name 是一个被 init 创建的局部变量
  return function displayName() { // displayName() 是内部函数,一个闭包
    console.log(name); // 使用了父函数中声明的变量
  }
}

function init2(fn) {
  var name = 'james'
  fn()
}
var f = init();

init2(f)

var f = init();
var name = 'james'
f() //Mozilla